﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Snowdreamist.ComponentModel;
using Snowdreamist.Windows.Navigation.Primitives;

namespace Snowdreamist.Windows.Navigation
{
    /// <summary>
    /// Navigation journal
    /// </summary>
    public abstract class NavigationJournal : JournalBase<NavigationJournalEntry>
    {
        protected override void AdjustNavigationChange()
        {
            base.AdjustNavigationChange();

            if (!this.CanGoBack && this.Current != null)
                this.CanGoBack = this.Current.MetaJournal.CanGoBack;
            if (!this.CanGoForward && this.Current != null)
                this.CanGoForward = this.Current.MetaJournal.CanGoForward;
        }

        public override bool GoBack()
        {
            if (this.Current != null)
            {
                if (this.Current.MetaJournal.CanGoBack)
                    return this.Current.MetaJournal.GoBack();
            }

            return base.GoBack();
        }

        public override bool GoForward()
        {
            if (this.Current != null)
            {
                if (this.Current.MetaJournal.CanGoForward)
                    return this.Current.MetaJournal.GoForward();
            }

            return base.GoForward();
        }

        public virtual bool NavigateTo(MetaJournalEntry entry)
        {
            if (this.Current != null)
                return this.Current.MetaJournal.NavigateTo(entry);
            else
                return false;
        }

        #region internal

        internal abstract void OnMetaJournalChanged(MetaJournalEntry metaEntry);

        #endregion internal
    }
}